package redis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

import redis.clients.jedis.Jedis;

public class TestHash {
	static Jedis jedis = null;

    static {
        jedis = new Jedis("192.168.79.131", 6379);//redis服务器地址与端口号
        jedis.auth("211125");    }
    
    // 测试Java做为客户端连接redis
    public static void main(String[] args) {
    	System.out.println("服务启动..."+jedis.ping());
    	jedis.flushDB();
    }
    
    // 7.5.6 操作散列
    @Test
    public void hmsetTest() {
    	Map<String,String> map = new HashMap<String,String>();
    	map.put("content", "hello world");
    	map.put("author", "wxh");
    	String hash = jedis.hmset("article", map);
    	System.out.println(hash);
    }
    
    @Test
    public void hgetallTest() {
    	Map<String,String> map = jedis.hgetAll("article");
    	System.out.println(map);
    }
    
    @Test
    public void hkeysTest() {
    	Set<String> keys = jedis.hkeys("article");
    	System.out.println(keys);
    }
    
    @Test
    public void hvalsTest() {
    	List<String> vals = jedis.hvals("article");
    	System.out.println(vals);
    }
    
    @Test
    public void hdelTest() {
    	Long result = jedis.hdel("article","author");
    	System.out.println(result);
    }
}
